<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@next"></script>
</head>

<body>

  <div id="root"></div>
  <script>
    //组件 data methods 优先级高于mixin data methods 优先级
    //生命周期函数，先执行mixin里面的，再执行组件里面的
    //自定义的属性，组件中的属性优先级高于mixin属性的优先级
    const myMixin = {
      name: 5,
      data() {
        return {
          number: 2,
          count: 3
        }
      },
      created() {
        console.log('mixin created');
      },
      methods: {
        click() {
          console.log('mixin click');
        }
      }
    }
    const app = Vue.createApp({
      name: 4,
      data() {
        return {
          number: 1,
        }
      },
      created() {
        console.log('my created');
      },
      mixins: [myMixin],
      methods: {
        click() {
          console.log('my click');
        }
      },
      template:
        `<div>{{number}}</div><div>{{this.$options.name}}</div>
      <child/>
      <button @click="click">增加</button>`
    });
    app.config.optionMergeStrategies.number = (mixinVal, appValue) => {
      return mixinVal || appValue;
    }
    app.component('child', {
      mixins: [myMixin],
      template: `<div>{{count}}</div>`
    })
    //全局mixin
    // app.mixin({

    // })
    const vm = app.mount('#root');
  </script>
</body>

</html>